const api = require("../../api/sop");
const { err } = require("../../utils/wxapi");
Page({
  /**
   * 页面的初始数据
   */
  data: { list: [], page: 1, limit: 20, total: 0 },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getlist();
  },
  async getlist() {
    try {
      const { page, limit, list } = this.data;
      const data = JSON.stringify({ userId: wx.getStorageSync("userId") });
      const res = await api.getcollect({ page, limit, data });
      console.log(res);
      if (res.respCode === 200) {
        const newlist = JSON.parse(res.source);
        const total = res.pageTotal;
        const updatelist = page > 1 ? [...list, ...newlist] : newlist;
        this.setData({ list: updatelist, total });
      }
    } catch (error) {
      err(error);
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const { page, total, list } = this.data;
    if (list.length < total) {
      this.setData({ page: page + 1 });
      this.getlist();
    } else {
      toast("暂无更多内容");
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
